{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import math\n",
    "import numpy as np\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "headers = [\"buying\", \"maint\", \"doors\", \"persons\",\"lug_boot\", \"safety\", \"class\"]\n",
    "data = pd.read_csv(\"car_data.csv\", header=None, names=headers)\n",
    "\n",
    "data = data.sample(frac=1).reset_index(drop=True) # shuffle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for h in headers:\n",
    "    data[h] = data[h].astype('category')\n",
    "    data[h] = data[h].cat.codes\n",
    "\n",
    "data.set_index(\"class\", inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "size = len(data)\n",
    "train_size = int(math.floor(size * 0.7))\n",
    "train_data = data[:train_size]\n",
    "test_data = data[train_size:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='entropy', max_depth=None,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d_tree = DecisionTreeClassifier(criterion=\"entropy\")\n",
    "d_tree.fit(train_data, train_data.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Score with criterion = entropy: 0.9845857418111753\n"
     ]
    }
   ],
   "source": [
    "d_tree.predict(test_data.iloc[:, 0:6])\n",
    "score = d_tree.score(test_data, test_data.index)\n",
    "\n",
    "print('Score with criterion = entropy: {0}'.format(score))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d_tree = DecisionTreeClassifier(criterion=\"gini\")\n",
    "d_tree.fit(train_data, train_data.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Score with criterion = gini: 0.9865125240847784\n"
     ]
    }
   ],
   "source": [
    "d_tree.predict(test_data.iloc[:, 0:6])\n",
    "score = d_tree.score(test_data, test_data.index)\n",
    "\n",
    "print('Score with criterion = gini: {0}'.format(score))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAAEKCAYAAAAB0GKPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xd4lXW67vHvk04SIEBCKIEkdAJSA1Kto2DvHUEEGQuM\n08fxzJ6zZ59zZjPbmdk6iiICCuoWK4oODog40iIQOqGGhEBCSyhJ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sLpqqCMaUTUQ3CAgCVjuWR5C1fAO+cBJYIZndsEGP8Og8V1WGMZcuaJqvxdglqr+tvoG\nInIH8I2qPnL2ziIykKqiuR+YCNzgYFZjLptdwzCm5gqBxhdY9y1wv4i0hNNzLcdTdVpqqIh08iyP\nEJEunusYTVV1PvAzqqZgNcYn2RGGMTWkqodFZLmIbAZOAAerrdsiIr8DFopIAFAGPKeqP4jIE8AH\nIhLq2fx3VJXPFyISRtXRyc/r8s9iTE3YRW9jjDFesVNSxhhjvGKFYYwxxitWGMYYY7xihWGMMcYr\nVhjGGGO8YoVhjDHGK1YYxhhjvGKFYYwxxiv/H0qwua3Au/mwAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7ff0a2a4d9b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.ensemble import RandomForestClassifier\n",
    "\n",
    "def randomForestScores(limitTrees, train_data):\n",
    "    scores = []\n",
    "    for i in range(1, limitTrees):\n",
    "        toFitTrainData = train_data\n",
    "        d_tree = RandomForestClassifier(n_estimators=i, criterion='entropy')\n",
    "        d_tree.fit(toFitTrainData, toFitTrainData.index)\n",
    "        \n",
    "        d_tree.predict(test_data.iloc[:, 0:6])\n",
    "        score = d_tree.score(test_data, test_data.index)\n",
    "        scores.append(score)\n",
    "    return scores\n",
    "\n",
    "scores = randomForestScores(11, train_data) # teste de 1 a 10 árvores\n",
    "\n",
    "plt.plot(range(1, 11), scores)\n",
    "plt.xlabel('trees')\n",
    "plt.ylabel('score')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
